//P2887 [USACO07NOV] Sunscreen G:https://www.luogu.com.cn/problem/P2887


#include <iostream>
#include <algorithm>

using namespace std;

const int N = 2510;

struct node
{
	int l;
	int r;
}a[N], b[N];

int c, l;

bool cmp1(const node& n1, const node& n2)
{
	return n1.r < n2.r;
}


bool cmp2(const node& n1, const node& n2)
{
	return n1.l < n2.l;
}

int main()
{
	cin >> c >> l;
	for (int i = 0; i < c; i++)
	{
		scanf("%d%d", &a[i].l, &a[i].r);
	}
	for (int i = 0; i < l; i++)
	{
		scanf("%d%d", &b[i].l, &b[i].r);
	}

	sort(a, a + c, cmp1);
	sort(b, b + l, cmp2);

	int ret = 0;
	int pa = 0;
	int pb = 0;
	while (pa < c && pb < l)
	{
		int left = a[pa].l;
		int right = a[pa].r;
		pb = 0;
		while (pb < l)
		{
			if(b[pb].r == 0)
			{
				pb++;
			}
			else if (b[pb].l < left)
			{
				pb++;
			}
			else if (b[pb].l > right)
			{
				pa++;
				break;
			}
			else
			{
				b[pb].r--;
				ret++;
				pa++;
				break;
			}
		}
	}
	cout << ret;

	return 0;
}
